﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace PhanMemDao
{
    public class ThucHanhDao
    {
        DataAccess da = new DataAccess();
        //Lay tat ca ten chuong cua mon hoc C
        public DataTable ten_chuong()
        {
            DataTable dt = new DataTable();
            string str = "Select * from khai_niem_cb";
            dt = da.lay_du_lieu(str);
            return dt;
        }
        //Lay tat ca ten bai trong cac chuong
        public DataTable ten_bai(string ten_kn)
        {
            DataTable dt = new DataTable();
            string str = "Select ten_bhct from bai_hoc_ct where ten_kn =N'" + ten_kn + "'";
            dt = da.lay_du_lieu(str);
            return dt;
        }
        //Lay ma so cua mot bai viet
        public int ma_bai_hoc_ct(string ten_bai)
        {
            DataTable dt = new DataTable();
            string str = " Select ma_bhct from bai_hoc_ct where ten_bhct =N'" + ten_bai + "'";
            dt = da.lay_du_lieu(str);
            if (dt.Rows.Count > 0)
                return Convert.ToInt32(dt.Rows[0]["ma_bhct"]);
            else
                return -1;
        }
        //lay tat ca cac bai tap trong mot bai hoc
        public DataTable noi_dung_bt(string ten_bai)
        {
            int ma_bai = ma_bai_hoc_ct(ten_bai);
            DataTable dt = new DataTable();
            if (ma_bai >= 0)
            {
                string str = " Select * from bai_tap where ma_bhct='" + ma_bai + "'";
                dt = da.lay_du_lieu(str);
            }
            return dt;
        }
        //luu dien
        public void luudiem(string ten, int diem, string tenbai)
        {
            int mabv = ma_bai_hoc_ct(tenbai);
            string sql = "insert into diem (ma_bhct,so_diem,ten_nguoi_dung,ngay_lam) values ('" + mabv + "','" + diem + "',N'" + ten + "',getdate())";
            da.thao_tac_du_lieu(sql);
        }
        //lay danh sach va noi dung cac ham
        public DataTable TimKiemTV(string tenTV)
        {
            DataTable dt = new DataTable();
            string sql = "select ten_tv, ham from thu_vien where ten_tv like N'%" + tenTV + "%'";
            dt = da.lay_du_lieu(sql);
            return dt;
        }
    }
}